/*-//GEN-BEGIN:copyright
 * ForBILE - Framework for Building Interactive Learning Environments
 * Computing Institute - Federal University of Alagoas - Brazil
 * Group of Otimization of the Web
 *
 * Copyright (C) 2007 Ig Bittencourt (ig.ibert@gmail.com)
 *		      Camila Nunes (camilapbnunes@hotmail.com)
 *	              Marcos Tadeu (zero.ufal@gmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *///GEN-END:copyright
package br.ufal.ic.utils;

import java.util.logging.Logger;
import com.hp.hpl.jena.reasoner.rulesys.builtins.GE;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

/**
 * Configuration.java
 *
 * <p>A full description of this class.
 *
 * @see SomeRelatedClass.
 *
 * @author <a href="mailto:ig.ibert@gmail.com">ig</a>.
 * @since 0.1
 * @version 0.1
 *
 */
public class Configuration {
    
    // Constants -----------------------------------------------------
    
    public static final String FILE_NAME = "/configuration.properties";
    public static final String USER_PATH = "user.home";        
    
    // Attributes ----------------------------------------------------
    
    private Properties properties;
    
    // Static --------------------------------------------------------        
    
    private static Configuration instance;
    
    private static Logger logger;
    
    static {
        logger = Logger.getLogger(Configuration.class.getName());
    }
    
    // Constructors --------------------------------------------------
    
    /** 
     * Creates a new instance of Configuration.     
     */
    public Configuration() {
        properties = new Properties();
        
        try {
            String home = System.getProperty(USER_PATH);            
            String path = home + "/emathema" + FILE_NAME;           
            properties.load(new FileInputStream(new File(path)));
        } catch (FileNotFoundException ex) {
            throw new IllegalArgumentException("Configuration file not found.");
        } catch (IOException ex) {
            throw new IllegalArgumentException("Troubles trying to open the file.");
        }
    }
    
    // Public --------------------------------------------------------
    
    /**
     * Gets the unique instance of the Configuration. 
     * 
     * @return The unique configuration.
     */
    public synchronized static Configuration getInstance() {
        if (instance == null) {
            instance = new Configuration();
        }
        
        return instance;
    }
    
    /**
     * Gets the value. 
     *
     * @param key The value.
     *
     * @return The value inside the file.
     */
    public String getValue(final String key) {
        if (!properties.containsKey(key)) {
            throw new IllegalArgumentException("Key not found");
        }                
        
        return properties.getProperty(key);
    }
    
    // Z implementation ----------------------------------------------
    
    // Y overrides ---------------------------------------------------
    
    // Package protected ---------------------------------------------
    
    // Protected -----------------------------------------------------
    
    // Private -------------------------------------------------------
    
    // Inner classes -------------------------------------------------
    
}
